home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / fade-outline.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  6.1 KB  |  174 lines

  1. ; fade-outline.scm
  2. ; version 1.1.11a
  3. ;
  4. ; This GIMP script_fu operates on a single Layer
  5. ; It blends the outline boarder from one to another transparency level
  6. ; by adding a layer_mask that follows the shape of the selection.
  7. ; usually from 100% (white is full opaque) to 0% (black is full transparent)
  8. ;
  9. ; The user can specify the thickness of the fading border
  10. ; that is used to blend from transparent to opaque
  11. ; and the Fading direction (shrink or grow).
  12. ;
  13. ; The outline is taken from the current selection
  14. ; or from the layers alpha channel if no selection is active.
  15. ;
  16. ; Optional you may keep the generated layermask or apply
  17. ; it to the layer 
  18.  
  19. ;
  20. ; The GIMP -- an image manipulation program
  21. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  22. ; This program is free software; you can redistribute it and/or modify
  23. ; it under the terms of the GNU General Public License as published by
  24. ; the Free Software Foundation; either version 2 of the License, or
  25. ; (at your option) any later version.
  26. ; This program is distributed in the hope that it will be useful,
  27. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29. ; GNU General Public License for more details.
  30. ; You should have received a copy of the GNU General Public License
  31. ; along with this program; if not, write to the Free Software
  32. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33.  
  34.  
  35. ; Define the main function:
  36.  
  37. (define (script-fu-fade-outline   inImage
  38.                                   inLayer
  39.                                   inBorderSize
  40.                                   inFadeFrom
  41.                                   inFadeTo
  42.                                   inGrowingSelection
  43.                                   inApplyMask
  44.                                   inClearUnselected)
  45.   (let* ((l-idx 0)
  46.      (l-has-selection TRUE))
  47.  
  48.     (gimp-context-push)
  49.  
  50.     ; check Fade from and To Values (and force values from 0% to 100%)
  51.     (if (> inFadeFrom 100) (begin (set! inFadeFrom 100 )) )
  52.     (if (< inFadeFrom 0)   (begin (set! inFadeFrom 0 )) )
  53.     (if (> inFadeTo 100) (begin (set! inFadeTo 100 )) )
  54.     (if (< inFadeTo 0)   (begin (set! inFadeTo 0 )) )
  55.     
  56.     (set! l-from-gray (* inFadeFrom 255))
  57.     (set! l-to-gray (* inFadeTo 255))
  58.     (set! l-step (/  (- l-from-gray l-to-gray) (+ inBorderSize 1)))
  59.     (set! l-gray l-to-gray)
  60.  
  61.     ; do nothing if the layer is a layer mask
  62.     (if (= (car (gimp-drawable-is-layer-mask inLayer)) 0)
  63.     (begin
  64.  
  65.       (gimp-image-undo-group-start inImage)
  66.               
  67.       ; if the layer has no alpha add alpha channel
  68.       (if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
  69.           (begin
  70.         (gimp-layer-add-alpha inLayer)))
  71.  
  72.           ; if the layer is the floating selection convert to normal layer
  73.           ; because floating selection cant have a layer mask
  74.       (if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
  75.           (begin
  76.         (gimp-floating-sel-to-layer inLayer)))
  77.  
  78.           ; if there is no selection we use the layers alpha channel
  79.       (if (= (car (gimp-selection-is-empty inImage)) TRUE)
  80.           (begin
  81.         (set! l-has-selection FALSE)
  82.         (gimp-selection-layer-alpha inLayer)))
  83.  
  84.       (gimp-selection-sharpen inImage)
  85.  
  86.           ; apply the existing mask before creating a new one
  87.       (gimp-layer-remove-mask inLayer 0)
  88.  
  89.       (if (= inClearUnselected  TRUE)
  90.           (begin
  91.         (set! l-mask (car (gimp-layer-create-mask inLayer ADD-BLACK-MASK))))
  92.           (begin
  93.         (set! l-mask (car (gimp-layer-create-mask inLayer ADD-WHITE-MASK)))))
  94.  
  95.       (gimp-layer-add-mask inLayer l-mask)
  96.  
  97.       (if (= inGrowingSelection  TRUE)
  98.           (begin
  99.         (set! l-gray l-from-gray)
  100.         (set! l-from-gray l-to-gray)
  101.         (set! l-to-gray l-gray)
  102.         (set! l-step (/  (- l-from-gray l-to-gray) (+ inBorderSize 1)))
  103.         (set! l-orig-selection  (car (gimp-selection-save inImage)))
  104.         (gimp-selection-invert inImage)))
  105.                                            
  106.       (while (<= l-idx inBorderSize)
  107.                  (if (= l-idx inBorderSize)
  108.                      (begin
  109.                (set! l-gray l-from-gray)))
  110.  
  111.          (gimp-context-set-background (list (/ l-gray 100) (/ l-gray 100) (/ l-gray 100)))
  112.          (gimp-edit-fill l-mask BACKGROUND-FILL)
  113.          (set! l-idx (+ l-idx 1))
  114.          (set! l-gray (+ l-gray l-step))
  115.          (gimp-selection-shrink inImage 1)
  116.          ; check if selection has shrinked to none
  117.          (if (= (car (gimp-selection-is-empty inImage)) TRUE)
  118.              (begin
  119.                (set! l-idx (+ inBorderSize 100))     ; break the while loop
  120.                )))
  121.               
  122.       (if (= inGrowingSelection  TRUE)
  123.           (begin
  124.         (gimp-selection-load l-orig-selection)
  125.         (gimp-context-set-background (list (/ l-to-gray 100) (/ l-to-gray 100) (/ l-to-gray 100)))
  126.         (gimp-edit-fill l-mask BACKGROUND-FILL)
  127.         (gimp-selection-grow inImage inBorderSize)
  128.         (gimp-selection-invert inImage)
  129.         (if (= inClearUnselected  TRUE)
  130.             (begin
  131.             ;(gimp-context-set-background (list (/ l-from-gray 100) (/ l-from-gray 100) (/ l-from-gray 100)))
  132.               (gimp-context-set-background (list 0 0 0)))
  133.  
  134.             (begin
  135.               (gimp-context-set-background (list 255 255 255))))
  136.  
  137.         (gimp-edit-fill l-mask BACKGROUND-FILL)
  138.         (gimp-image-remove-channel inImage l-orig-selection)))
  139.  
  140.       (if (=  inApplyMask TRUE)
  141.           (begin
  142.         (gimp-layer-remove-mask inLayer 0)))
  143.  
  144.       (if (= l-has-selection FALSE)
  145.           (gimp-selection-none inImage))
  146.  
  147.       (gimp-image-undo-group-end inImage)
  148.       (gimp-displays-flush)))
  149.  
  150.     (gimp-context-pop)))
  151.  
  152.  
  153. (script-fu-register "script-fu-fade-outline"
  154.             _"_Fade Outline..."
  155.             "Blend the Layers outline border from one alpha value (opaque) to another (transparent) by generating a Layermask"
  156.             "Wolfgang Hofer <hof@hotbot.com>"
  157.             "Wolfgang Hofer"
  158.             "10 Nov 1999"
  159.             "RGB* GRAY*"
  160.             SF-IMAGE       "The image"   0
  161.             SF-DRAWABLE    "The layer"   0
  162.             SF-ADJUSTMENT _"Border size" '(10 1 300 1 10 0 1)
  163.             SF-ADJUSTMENT _"Fade from %" '(100 0 100 1 10 0 0)
  164.             SF-ADJUSTMENT _"Fade to   %" '(0 0 100 1 10 0 0)
  165.             SF-TOGGLE     _"Use growing selection"     FALSE
  166.             SF-TOGGLE     _"Apply generated layermask" FALSE
  167.             SF-TOGGLE     _"Clear unselected maskarea" TRUE)
  168.  
  169. (script-fu-menu-register "script-fu-fade-outline"
  170.              _"<Image>/Script-Fu/Selection")
  171.